package com.property.manage.controller.repair;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.renovation.RenovationVo;
import com.property.manage.model.repair.RepairVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.renovation.RenovationService;
import com.property.manage.service.repair.RepairService;
import com.property.manage.service.system.SysSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "报修登记")
@RestController
@RequestMapping("/repair")
@AllArgsConstructor
@Validated
public class RepairController {
    @Autowired
    private RepairService repairService;

    @ApiOperation("列表")
    @GetMapping("/page")
    public CustomPage<RepairVo> getPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                        @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                        @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                        @ApiParam("开始时间") @RequestParam(value = "startTime", required = false) String startTime,
                                        @ApiParam("结束时间") @RequestParam(value = "endTime", required = false) String endTime){
        return repairService.page(pageNo,pageSize,villageId,startTime,endTime);
    }


    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(
                    @ApiParam("报修时间")@RequestParam(value = "rTime")@NotNull(message = "报修时间不能为空") LocalDate rTime,
                    @ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                    @ApiParam("报修内容")@RequestParam(value = "content")@NotBlank(message = "报修内容不能为空") String content,
                    @ApiParam("报修人")@RequestParam(value = "name")@NotBlank(message = "报修人不能为空") String name,
                    @ApiParam("手机号码")@RequestParam(value = "phone",required = false) String phone
    ){
      repairService.add(villageId,content,name,phone,rTime);   }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("报修时间")@RequestParam(value = "rTime")@NotNull(message = "报修时间不能为空") LocalDate rTime,
                       @ApiParam("维修时间")@RequestParam(value = "pTime",required = false) LocalDate pTime,
                       @ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                       @ApiParam("报修内容")@RequestParam(value = "content")@NotBlank(message = "报修内容不能为空") String content,
                       @ApiParam("报修人")@RequestParam(value = "name")@NotBlank(message = "报修人不能为空") String name,
                       @ApiParam("手机号码")@RequestParam(value = "phone",required = false) String phone,
                       @ApiParam("维修人")@RequestParam(value = "personnel",required = false) String personnel
    ){
      repairService.update(id,villageId,content,name,phone,rTime,personnel,pTime);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        repairService.delete(id);
    }


}
